﻿import com.gamepackage.events.*;

class com.gamepackage.util.FPS
{
	static private var frameTime: Number = 0;
	static private var ms: Number;
	static private var checkCall: Call = new Call( FPS , check );
	
	static function load(): Void
	{
		ms = getTimer();
		Impuls.connect( checkCall );
	}
	
	static function unload(): Void
	{
		Impuls.disconnect( checkCall );
	}
	
	static function check(): Void
	{
		frameTime = getTimer() - ms;
		ms = getTimer();
	}
	
	static function getCurrentFPS(): Number
	{
		if ( frameTime ) return int( 1000 / frameTime );
		return 0;
	}
	
	static function toTextField( textField: TextField ): Void
	{
		load();
		Impuls.connect( new Setter( textField , 'text' , FPS , getCurrentFPS ) );
	}
}